"""Definition of the subdistrict content type
"""

from zope.interface import implements

from Products.Archetypes import atapi
from Products.ATContentTypes.content import folder
from Products.ATContentTypes.content import schemata

from Products.CMFCore.utils import getToolByName
from zope.interface import implements
from zope.component import getMultiAdapter
from Acquisition import aq_inner

#from Products.ATContentTypes.configuration import zconf
#from Products.validation.config import validation
#from Products.validation.validators.SupplValidators import MaxSizeValidator
#from Products.validation import V_REQUIRED
#
#validation.register(MaxSizeValidator('checkNewsImageMaxSize',
#                                     maxsize=zconf.ATNewsItem.max_file_size))

# -*- Message Factory Imported Here -*-
from my315ok.fangcan import fangcanMessageFactory as _

from my315ok.fangcan.interfaces import Isubdistrict
from my315ok.fangcan.config import PROJECTNAME
from Products.ATContentTypes.content.newsitem import ATNewsItem,ATNewsItemSchema
#imagefield = ATNewsItemSchema.get("image")

#subdistrictSchema = folder.ATFolderSchema.copy() + atapi.Schema((
subdistrictSchema = ATNewsItemSchema.copy() + atapi.Schema((
    # -*- Your Archetypes field definitions here ... -*-

    atapi.FloatField(
        'longitude',
        storage=atapi.AnnotationStorage(),
        widget=atapi.DecimalWidget(
            label=_(u"longitude"),
            description=_(u""),
        ),
        default=_(u"112.885666"),
        validators=('isDecimal'),
    ),


    atapi.FloatField(
        'latitude',
        storage=atapi.AnnotationStorage(),
        widget=atapi.DecimalWidget(
            label=_(u"latitude"),
            description=_(u""),
        ),
        default=_(u"27.879506"),
        validators=('isDecimal'),
    ),   

   


    atapi.StringField(
        'Area',
        storage=atapi.AnnotationStorage(),
        widget=atapi.StringWidget(
            label=_(u"area name"),
            description=_(u""),
        ),
        required=True,
    ),


    atapi.StringField(
        'bigarea',
        storage=atapi.AnnotationStorage(),
        widget=atapi.StringWidget(
            label=_(u"big area"),
            description=_(u""),
        ),
    ),


    atapi.StringField(
        'address',
        storage=atapi.AnnotationStorage(),
        widget=atapi.StringWidget(
            label=_(u"address"),
            description=_(u""),
        ),
    ),


    atapi.StringField(
        'estate_type',
        storage=atapi.AnnotationStorage(),
        widget=atapi.StringWidget(
            label=_(u"estate type"),
            description=_(u""),
        ),
    ),


    atapi.StringField(
        'school',
        storage=atapi.AnnotationStorage(),
        widget=atapi.StringWidget(
            label=_(u"school"),
            description=_(u""),
        ),
    ),


    atapi.StringField(
        'middle_school',
        storage=atapi.AnnotationStorage(),
        widget=atapi.StringWidget(
            label=_(u"middle school"),
            description=_(u""),
        ),
    ),


    atapi.StringField(
        'traffic',
        storage=atapi.AnnotationStorage(),
        widget=atapi.StringWidget(
            label=_(u"traffic"),
            description=_(u""),
        ),
    ),


    atapi.StringField(
        'landscape',
        storage=atapi.AnnotationStorage(),
        widget=atapi.StringWidget(
            label=_(u"landscape"),
            description=_(u""),
        ),
    ),


    atapi.StringField(
        'shopping',
        storage=atapi.AnnotationStorage(),
        widget=atapi.StringWidget(
            label=_(u"shopping"),
            description=_(u""),
        ),
    ),


    atapi.StringField(
        'dining',
        storage=atapi.AnnotationStorage(),
        widget=atapi.StringWidget(
            label=_(u"dining"),
            description=_(u""),
        ),
    ),


    atapi.StringField(
        'hospital',
        storage=atapi.AnnotationStorage(),
        widget=atapi.StringWidget(
            label=_(u"hospital"),
            description=_(u""),
        ),
    ),


    atapi.StringField(
        'subdistrict_support',
        storage=atapi.AnnotationStorage(),
        widget=atapi.StringWidget(
            label=_(u"subdistrict support"),
            description=_(u""),
        ),
    ),


    atapi.FloatField(
        'greening_ratio',
        storage=atapi.AnnotationStorage(),
        widget=atapi.DecimalWidget(
            label=_(u"greening ratio"),
            description=_(u""),
        ),
        validators=('isDecimal'),
    ),


    atapi.FloatField(
        'capacity_ratio',
        storage=atapi.AnnotationStorage(),
        widget=atapi.DecimalWidget(
            label=_(u"capacity ratio"),
            description=_(u""),
        ),
        validators=('isDecimal'),
    ),


    atapi.IntegerField(
        'household_total',
        storage=atapi.AnnotationStorage(),
        widget=atapi.IntegerWidget(
            label=_(u"household total"),
            description=_(u""),
        ),
        validators=('isInt'),
    ),


    atapi.IntegerField(
        'parking_space',
        storage=atapi.AnnotationStorage(),
        widget=atapi.IntegerWidget(
            label=_(u"parking space"),
            description=_(u""),
        ),
        validators=('isInt'),
    ),


    atapi.FloatField(
        'building_area',
        storage=atapi.AnnotationStorage(),
        widget=atapi.DecimalWidget(
            label=_(u"building area"),
            description=_(u""),
        ),
        validators=('isDecimal'),
    ),


    atapi.FloatField(
        'floor_space',
        storage=atapi.AnnotationStorage(),
        widget=atapi.DecimalWidget(
            label=_(u"floor space"),
            description=_(u""),
        ),
        validators=('isDecimal'),
    ),


    atapi.StringField(
        'estate_business',
        storage=atapi.AnnotationStorage(),
        widget=atapi.StringWidget(
            label=_(u"estate business"),
            description=_(u""),
        ),
    ),


    atapi.StringField(
        'estate_management',
        storage=atapi.AnnotationStorage(),
        widget=atapi.StringWidget(
            label=_(u"estate management company"),
            description=_(u""),
        ),
    ),


    atapi.FloatField(
        'estate_fee',
        storage=atapi.AnnotationStorage(),
        widget=atapi.DecimalWidget(
            label=_(u"estate fee"),
            description=_(u""),
        ),
        validators=('isDecimal'),
    ),


    atapi.DateTimeField(
        'building_date',
        storage=atapi.AnnotationStorage(),
        widget=atapi.CalendarWidget(
            label=_(u"building date"),
            description=_(u""),
            starting_year=1990,
            show_hm=0,
        ),
        validators=('isValidDate','isDateBeforeToday'),
    ),

))

# Set storage on fields copied from ATFolderSchema, making sure
# they work well with the python bridge properties.
#subdistrictSchema.addField(imagefield)
subdistrictSchema['title'].storage = atapi.AnnotationStorage()
#subdistrictSchema['title'].enforceVocabulary = 1
subdistrictSchema['title'].vocabulary_factory =u"my315ok.fangcan.subdistrict"
subdistrictSchema['title'].widget = atapi.SelectionWidget(label= _(u'name of the subdistrict'),
                                                          description=_(u""),)
#subdistrictSchema['title'].widget.
subdistrictSchema['description'].storage = atapi.AnnotationStorage()
subdistrictSchema['imageCaption'].widget.visible = 0
subdistrictSchema['text'].widget.visible = 1
subdistrictSchema['text'].widget.allow_file_upload=False
subdistrictSchema['image'].widget.description = _(u'main photo of the subdistrict')
subdistrictSchema.moveField('text', pos='bottom')
subdistrictSchema['longitude'].widget.visible ={'edit':'visible','view':'invisible'}
subdistrictSchema['latitude'].widget.visible ={'edit':'visible','view':'invisible'}

schemata.finalizeATCTSchema(
    subdistrictSchema,
#    folderish=True,
    moveDiscussion=False
)


class subdistrict(ATNewsItem):
    """subdistrict"""
    implements(Isubdistrict)

    meta_type = "subdistrict"
    schema = subdistrictSchema
    _at_rename_after_creation = True
    


    title = atapi.ATFieldProperty('title')
    description = atapi.ATFieldProperty('description')

    # -*- Your ATSchema to Python Property Bridges Here ... -*-
    longitude = atapi.ATFieldProperty('longitude')

    latitude = atapi.ATFieldProperty('latitude')

#    image = atapi.ATFieldProperty('image')

#    average_price = atapi.ATFieldProperty('average_price')
#
#    rent_amount = atapi.ATFieldProperty('rent_amount')
#
#    secondhand_amount = atapi.ATFieldProperty('secondhand_amount')

    Area = atapi.ATFieldProperty('Area')

    bigarea = atapi.ATFieldProperty('bigarea')

    address = atapi.ATFieldProperty('address')

    estate_type = atapi.ATFieldProperty('estate_type')

    school = atapi.ATFieldProperty('school')

    middle_school = atapi.ATFieldProperty('middle_school')

    traffic = atapi.ATFieldProperty('traffic')

    landscape = atapi.ATFieldProperty('landscape')

    shopping = atapi.ATFieldProperty('shopping')

    dining = atapi.ATFieldProperty('dining')

    hospital = atapi.ATFieldProperty('hospital')

    subdistrict_support = atapi.ATFieldProperty('subdistrict_support')

    greening_ratio = atapi.ATFieldProperty('greening_ratio')

    capacity_ratio = atapi.ATFieldProperty('capacity_ratio')

    household_total = atapi.ATFieldProperty('household_total')

    parking_space = atapi.ATFieldProperty('parking_space')

    building_area = atapi.ATFieldProperty('building_area')

    floor_space = atapi.ATFieldProperty('floor_space')

    estate_business = atapi.ATFieldProperty('estate_business')

    estate_management = atapi.ATFieldProperty('estate_management')

    estate_fee = atapi.ATFieldProperty('estate_fee')

    building_date = atapi.ATFieldProperty('building_date')


atapi.registerType(subdistrict, PROJECTNAME)
